home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / makeindex / mkind.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-26  |  13.2 KB  |  534 lines

  1. /*
  2.  *
  3.  * Copyright (C) 1987     Pehong Chen    (phc@renoir.berkeley.edu)
  4.  * Computer Science Division
  5.  * University of California, Berkeley
  6.  *
  7.  */
  8.  
  9. /***********************************************************************
  10.  
  11.                            INSTALLATION NOTES
  12.                               [14-Jan-88]
  13.  
  14.    At compile-time (or here, if compile-time definition is not
  15.    available), set non-zero ONE OS_xxxx operating system flag, and if
  16.    more than one compiler is available, ONE compiler flag:
  17.  
  18.     Operating Systems        Compiler(s)
  19.     =================        ===========
  20.     OS_ATARI
  21.     OS_PCDOS            IBM_PC_MICROSOFT
  22.     OS_TOPS20            KCC_20 or PCC_20
  23.     OS_VAXVMS
  24.     OS_UNIX
  25.     =================        ===========
  26.  
  27.    If no OS_xxxx symbol is defined, OS_UNIX is assumed.
  28.  
  29.    If draft ANSI C prototypes are supported, define the symbol
  30.    ANSI_PROTOTYPES in the appropriate OS_xxxx section below, and insert
  31.    #include's for the standard system files which define library
  32.    prototypes.  Unfortunately, these are scattered about in several
  33.    files in draft ANSI C; the IBM_PC_MICROSOFT section below is an
  34.    example which should be close for other implementations.
  35.  
  36.    All function declarations in MakeIndex are contained at the end of
  37.    this file.  If ANSI_PROTOTYPES is not selected, then all the standard
  38.    library functions must be declared explicitly.
  39.  
  40.    If the host system restricts external names to 6 characters, set
  41.    SHORTNAMES non-zero in the appropriate OS_xxxx section below.
  42. */
  43.  
  44. /**********************************************************************/
  45. /* Establish needed operating symbols (defaulting to OS_UNIX if none
  46.    specified at compile time) */
  47.  
  48. #ifndef OS_ATARI
  49. #define OS_ATARI 0
  50. #endif
  51.  
  52. #ifndef OS_PCDOS
  53. #define OS_PCDOS 0
  54. #endif
  55.  
  56. #ifndef IBM_PC_MICROSOFT
  57. #define IBM_PC_MICROSOFT 0
  58. #endif
  59.  
  60. #ifndef OS_TOPS20
  61. #define OS_TOPS20 0
  62. #endif
  63.  
  64. #ifndef KCC_20
  65. #define KCC_20 0
  66. #endif
  67.  
  68. #ifndef PCC_20
  69. #define PCC_20 0
  70. #endif
  71.  
  72. #ifndef OS_UNIX
  73. #define OS_UNIX 0
  74. #endif
  75.  
  76. #ifndef OS_VAXVMS
  77. #define OS_VAXVMS 0
  78. #endif
  79.  
  80. #if    OS_TOPS20
  81. #if    (KCC_20 | PCC_20)
  82. #else
  83. #undef PCC_20
  84. #define PCC_20 1            /* PCC-20 is default for Tops-20 */
  85. #endif
  86. #endif
  87.  
  88. #if    (OS_PCDOS | OS_TOPS20 | OS_UNIX | OS_VAXVMS)
  89. #else
  90. #undef OS_UNIX
  91. #define OS_UNIX 1            /* Unix is default operating system */
  92. #endif
  93.  
  94. #if    OS_TOPS20
  95. #define SHORTNAMES 1
  96. #else
  97. #define SHORTNAMES 0
  98. #endif
  99.  
  100. #define ANSI_PROTOTYPES 0
  101.  
  102. #define qsort qqsort    /* avoid conflict with standard library routine */
  103.  
  104. /**********************************************************************/
  105.  
  106. #include    <stdio.h>
  107. #include    <ctype.h>
  108.  
  109. #if    IBM_PC_MICROSOFT
  110. #include    <io.h>        /* for function declarations */
  111. #include    <stddef.h>    /* for function declarations */
  112. #include    <stdlib.h>    /* for function declarations */
  113. #include    <string.h>    /* for function declarations */
  114. #undef ANSI_PROTOTYPES
  115. #define ANSI_PROTOTYPES    1    /* so we get full argument type checking */
  116. #endif /* IBM_PC_MICROSOFT */
  117.  
  118. #if    (IBM_PC_MICROSOFT | OS_VAXVMS)
  119. #define    index        strchr    /* convert old K&R form to ANSI form */
  120. #define rindex        strrchr    /* convert old K&R form to ANSI form */
  121. #endif
  122.  
  123. #if    PCC_20
  124. #define R_OK 0                /* PCC-20 access(file,mode) */
  125.                 /* only understands mode=0 */
  126. #endif
  127.  
  128. #if    SHORTNAMES
  129. /* Provide alternate external names which are unique in the first
  130. SIX characters as required for portability (and Oct. 1986 draft ANSI C) */
  131. #define    check_all        chk_all
  132. #define    check_idx        chk_idx
  133. #define    check_mixsym        chk_mix
  134. #define    compare_one        cmp_one
  135. #define    compare_page        cmp_page
  136. #define    compare_string        cmp_string
  137. #define    delim_n            dlm_n
  138. #define    delim_p            dlm_p
  139. #define    delim_r            dlm_r
  140. #define    encap_i            ecp_i
  141. #define    encap_p            ecp_p
  142. #define    encap_range        ecp_range
  143. #define    encap_s            ecp_s
  144. #define    group_skip        grp_skip
  145. #define    group_type        grp_type
  146. #define    idx_aclose        idxaclose
  147. #define    idx_actual        idxactual
  148. #define idx_keyword        idx_kwd
  149. #define    indent_length        ind_length
  150. #define indent_space        ind_space
  151. #define    lethead_flag        lth_flag
  152. #define    lethead_pre        lth_pre
  153. #define    lethead_suf        lth_suf
  154. #define    process_idx        prc_idx
  155. #define    process_precedence    prc_pre
  156. #define    range_lc        rng_lc
  157. #define    range_ptr        rng_ptr
  158. #define    scan_alpha_lower    scnalw
  159. #define    scan_alpha_upper    scnaup
  160. #define scan_arabic        scnarabic
  161. #define    scan_arg1        scna1
  162. #define    scan_arg2        scna2
  163. #define    scan_char        scnchr
  164. #define    scan_field        scnfld
  165. #define    scan_idx        scnidx
  166. #define    scan_key        scnkey
  167. #define    scan_no            scnno
  168. #define    scan_roman_lower    scnrlw
  169. #define    scan_roman_upper    scnrup
  170. #define    scan_spec        scnspc
  171. #define    scan_string        scnstr
  172. #define    scan_style        scnsty
  173. #define    setpagelen        spg_len
  174. #define    setpage_close        spg_close
  175. #define    setpage_open        spg_open
  176. #endif /* SHORTNAMES */
  177.  
  178. #if OS_VAXVMS
  179. #define EXIT vms_exit
  180. #else /* NOT OS_VAXVMS */
  181. #define EXIT exit
  182. #endif /* OS_VAXVMS */
  183.  
  184. #ifndef R_OK
  185. #define    R_OK        4    /* only symbol needed from sys/file.h */
  186. #endif
  187.  
  188. #undef    TRUE
  189. #define    TRUE            1
  190. #undef    FALSE
  191. #define    FALSE            0
  192. #undef    NULL
  193. #define    NULL            '\0'
  194.  
  195. #define    TAB            '\t'
  196. #define    LFD            '\n'
  197. #define    SPC            ' '
  198. #define    LSQ            '['
  199. #define    RSQ            ']'
  200. #define    BSH            '\\'
  201.  
  202. #if    OS_PCDOS
  203. #define    ENV_SEPAR        ';'
  204. #define    DIR_DELIM        '\\'
  205. #endif /* OS_PCDOS */
  206.  
  207. #if    OS_TOPS20
  208. #define    ENV_SEPAR        ','
  209. #define    DIR_DELIM        ':'
  210. #endif /* OS_TOPS20 */
  211.  
  212. #if    OS_UNIX
  213. #define    ENV_SEPAR        ':'
  214. #define    DIR_DELIM        '/'
  215. #endif /* OS_UNIX */
  216.  
  217. #if    OS_VAXVMS
  218. #define    ENV_SEPAR        ','
  219. #define    DIR_DELIM        ':'
  220. #endif /* OS_VAXVMS */
  221.  
  222. #define    SW_PREFIX        '-'
  223. #define    EXT_DELIM        '.'
  224. #define    ROMAN_SIGN        '*'
  225. #define EVEN            "even"
  226. #define ODD            "odd"
  227. #define ANY            "any"
  228.  
  229. #define    GET_CHAR        getc
  230.  
  231. #define    TOASCII(i)        (char)((i) + 48)
  232. #define    TOLOWER(C)        (char)((isupper(C)) ? tolower(C) : (C))
  233. #define    TOUPPER(C)        (char)((isupper(C)) ? (C) : toupper(C))
  234.  
  235. #define    STREQ(A, B)        (strcmp(A, B) == 0)
  236. #define    STRNEQ(A, B)        (strcmp(A, B) != 0)
  237.  
  238. #define    MESSAGE(F, S) { \
  239.     if (verbose) { \
  240.         fprintf(stderr, F, S); \
  241.         fflush(stderr); \
  242.     } \
  243.     fprintf(ilg_fp, F, S); \
  244. }
  245.  
  246. #define    FATAL(F, S) { \
  247.     fprintf(stderr, F, S); \
  248.     fprintf(stderr, USAGE, pgm_fn); \
  249.     EXIT(1); \
  250. }
  251.  
  252. #define    FATAL2(F, D1, D2) { \
  253.     fprintf(stderr, F, D1, D2); \
  254.     fprintf(stderr, USAGE, pgm_fn); \
  255.     EXIT(1); \
  256. }
  257.  
  258. #define    OPEN_IN(FP)        fopen(FP, "r")
  259. #define    OPEN_OUT(FP)        fopen(FP, "w")
  260. #define    CLOSE(FP)        fclose(FP)
  261.  
  262. #define    ISDIGIT(C)        ('0' <= C && C <= '9')
  263. #define    ISSYMBOL(C)        (('!' <= C && C <= '@') || \
  264.                  ('[' <= C && C <= '`') || \
  265.                  ('{' <= C && C <= '~'))
  266.  
  267. #define ARGUMENT_MAX        1024
  268. #define    LONG_MAX        144
  269. #define    LINE_MAX        72
  270. #define    STRING_MAX        64
  271. #define    ARABIC_MAX        4
  272. #define    ROMAN_MAX        16
  273. #define    PAGETYPE_MAX        5
  274. #define    PAGEFIELD_MAX        10
  275. #define    FIELD_MAX        3
  276. #define    NUMBER_MAX        16
  277.  
  278. #define    VERSION    "portable version 2.4 [20-Mar-88]"
  279. #define    PUT_VERSION { \
  280.     MESSAGE("This is %s, ", pgm_fn); \
  281.     MESSAGE("%s.\n", VERSION); \
  282.     need_version = FALSE; \
  283. }
  284.  
  285. #define    USAGE \
  286.    "Usage: %s [-ilqrc] [-s sty] [-o ind] [-t log] [-p no] [idx0 idx1 ...]\n"
  287.  
  288. #define    STYLE_PATH        "INDEXSTYLE"
  289. #define    INDEX_IDX        ".idx"
  290. #define    INDEX_ILG        ".ilg"
  291. #define    INDEX_IND        ".ind"
  292. #define    INDEX_LOG        ".log"
  293.  
  294. #define EMPTY            -9999
  295. #define ROML            0
  296. #define ROMU            1
  297. #define ARAB            2
  298. #define ALPL            3
  299. #define ALPU            4
  300. #define    DUPLICATE        9999
  301.  
  302. #define SYMBOL            -1
  303. #define ALPHA            -2
  304.  
  305. typedef struct KFIELD {
  306.     char        sf[FIELD_MAX][STRING_MAX];    /* sort key */
  307.     char        af[FIELD_MAX][STRING_MAX];    /* actual key */
  308.     int        group;                /* key group */
  309.     char        lpg[NUMBER_MAX];        /* literal page */
  310.     short        npg[PAGEFIELD_MAX];        /* page field array */
  311.     short        count;                /* page field count */
  312.     short        type;                /* page number type */
  313.     char        encap[STRING_MAX];        /* encapsulator */
  314.     char        *fn;                /* input filename */
  315.     int        lc;                /* line number */
  316. } FIELD, *FIELD_PTR;
  317.  
  318. typedef struct KNODE {
  319.     FIELD        data;
  320.     struct KNODE    *next;
  321. } NODE, *NODE_PTR;
  322.  
  323. extern    int    letter_ordering;
  324. extern    int    compress_blanks;
  325. extern    int    init_page;
  326. extern    int    merge_page;
  327. extern    int    even_odd;
  328. extern    int    verbose;
  329.  
  330. extern    char    idx_keyword[LONG_MAX];
  331. extern    char    idx_aopen;
  332. extern    char    idx_aclose;
  333. extern    char    idx_level;
  334. extern    char    idx_ropen;
  335. extern    char    idx_rclose;
  336. extern    char    idx_quote;
  337. extern    char    idx_actual;
  338. extern    char    idx_encap;
  339. extern    char    idx_escape;
  340.  
  341. extern    char    page_comp[LONG_MAX];
  342. extern    int    page_offset[PAGETYPE_MAX];
  343.  
  344. extern    char    preamble[LONG_MAX];
  345. extern    char    postamble[LONG_MAX];
  346. extern    char    setpage_open[LONG_MAX];
  347. extern    char    setpage_close[LONG_MAX];
  348. extern    char    group_skip[LONG_MAX];
  349. extern    char    lethead_pre[LONG_MAX];
  350. extern    char    lethead_suf[LONG_MAX];
  351. extern    int    lethead_flag;
  352. extern    int    prelen;
  353. extern    int    postlen;
  354. extern    int    skiplen;
  355. extern    int    headprelen;
  356. extern    int    headsuflen;
  357. extern    int    setpagelen;
  358.  
  359. extern    char    item_r[FIELD_MAX][LONG_MAX];
  360. extern    char    item_u[FIELD_MAX][LONG_MAX];
  361. extern    char    item_x[FIELD_MAX][LONG_MAX];
  362. extern    int    ilen_r[FIELD_MAX];
  363. extern    int    ilen_u[FIELD_MAX];
  364. extern    int    ilen_x[FIELD_MAX];
  365.  
  366. extern    char    delim_p[FIELD_MAX][LONG_MAX];
  367. extern    char    delim_n[LONG_MAX];
  368. extern    char    delim_r[LONG_MAX];
  369.  
  370. extern    char    encap_p[LONG_MAX];
  371. extern    char    encap_i[LONG_MAX];
  372. extern    char    encap_s[LONG_MAX];
  373.  
  374. extern    int    linemax;
  375. extern    char    indent_space[LONG_MAX];
  376. extern    int    indent_length;
  377.  
  378. extern    FILE    *idx_fp;
  379. extern    FILE    *sty_fp;
  380. extern    FILE    *ind_fp;
  381. extern    FILE    *ilg_fp;
  382. extern    char    *idx_fn;
  383. extern    char    sty_fn[];
  384. extern    char    *pgm_fn;
  385. extern    char    *ind_fn;
  386. extern    char    *ilg_fn;
  387. extern    char    ind[];
  388. extern    char    ilg[];
  389. extern    char    pageno[];
  390.  
  391. extern    FIELD_PTR    *idx_key;
  392. extern    NODE_PTR    head;
  393. extern    NODE_PTR    tail;
  394.  
  395. extern    int     idx_dot;
  396. extern    int    idx_tt;
  397. extern    int    idx_gt;
  398. extern    int    idx_et;
  399. extern    int    idx_dc;
  400.  
  401. #define DOT            "."
  402. #define    DOT_MAX            1000
  403. #define    CMP_MAX            1500
  404.  
  405. #define IDX_DOT(MAX) { \
  406.     idx_dot = TRUE; \
  407.     if (idx_dc++ == 0) { \
  408.         if (verbose) { \
  409.             fprintf(stderr, DOT); \
  410.             fflush(stderr); \
  411.         } \
  412.         fprintf(ilg_fp, DOT); \
  413.     } \
  414.     if (idx_dc == MAX) \
  415.         idx_dc = 0; \
  416. }
  417.  
  418. #define ALL_DONE { \
  419.     if (fn_no > 0) { \
  420.         if (verbose) \
  421.             fprintf(stderr, "Overall %d files read (%d entries accepted, %d rejected).\n", \
  422.                    fn_no+1, idx_gt, idx_et); \
  423.         fprintf(ilg_fp, "Overall %d files read (%d entries accepted, %d rejected).\n", \
  424.                fn_no+1, idx_gt, idx_et); \
  425.     } \
  426. }
  427.  
  428. #define    DONE(A, B, C, D) { \
  429.     if (verbose) \
  430.         fprintf(stderr, "done (%d %s, %d %s).\n", (A), B, C, D); \
  431.     fprintf(ilg_fp, "done (%d %s, %d %s).\n", (A), B, C, D); \
  432. }
  433.  
  434. #if    ANSI_PROTOTYPES
  435. static    void    check_all(char *fn,int ind_given,int ilg_given,int log_given);
  436. static    void    check_idx(char *fn,int open_fn);
  437. static    int    check_mixsym(char *x,char *y);
  438. static    int    compare(struct KFIELD * *a,struct KFIELD * *b);
  439. static    int    compare_one(char *x,char *y);
  440. static    int    compare_page(struct KFIELD * *a,struct KFIELD * *b);
  441. static    int    compare_string(char *a,char *b);
  442. static    int    count_lfd(char *str);
  443. static    void    find_pageno(void);
  444. static    void    flush_line(int print);
  445. extern    void    gen_ind(void);
  446. extern    int    group_type(char *str);
  447. static    void    insert_page(void);
  448. extern    int    main(int argc,char * *argv);
  449. static    int    make_entry(int n);
  450. static    void    make_item(void);
  451. static    int    make_key(void);
  452. static    void    new_entry(void);
  453. static    int    next_nonblank(void);
  454. static    void    old_entry(void);
  455. static    void    open_sty(char *fn);
  456. static    int    page_diff(struct KFIELD *a,struct KFIELD *b);
  457. static    void    prepare_idx(void);
  458. static    void    process_idx(char * *fn,int use_stdin,int sty_given,int ind_given,int ilg_given,int log_given);
  459. static    int    process_precedence(void);
  460. extern    void    qsort(char *base,int n,int size,int (*)(char*,char*));
  461. static    void    qst(char *base, char *max);
  462. static    int    scan_alpha_lower(char *no,short *npg,short *count);
  463. static    int    scan_alpha_upper(char *no,short *npg,short *count);
  464. static    int    scan_arabic(char *no,short *npg,short *count);
  465. static    int    scan_arg1(void);
  466. static    int    scan_arg2(void);
  467. static    int    scan_char(char *c);
  468. static    int    scan_field(int *n,char *field,int ck_level,int ck_encap,int ck_actual);
  469. extern    void    scan_idx(void);
  470. static    int    scan_key(struct KFIELD *data);
  471. static    int    scan_no(char *no,short *npg,short *count,short *type);
  472. static    int    scan_roman_lower(char *no,short *npg,short *count);
  473. static    int    scan_roman_upper(char *no,short *npg,short *count);
  474. static    int    scan_spec(char *spec);
  475. static    int    scan_string(char *str);
  476. extern    void    scan_sty(void);
  477. extern    void    sort_idx(void);
  478. extern    int    strtoint(char *str);
  479. static    void    wrap_line(int print);
  480. #else
  481. static    void    check_all();
  482. static    void    check_idx();
  483. static    int    check_mixsym();
  484. static    int    compare();
  485. static    int    compare_one();
  486. static    int    compare_page();
  487. static    int    compare_string();
  488. static    int    count_lfd();
  489. static    void    find_pageno();
  490. static    void    flush_line();
  491. extern    void    gen_ind();
  492. extern    int    group_type();
  493. static    void    insert_page();
  494. extern    int    main();
  495. static    int    make_entry();
  496. static    void    make_item();
  497. static    int    make_key();
  498. static    void    new_entry();
  499. static    int    next_nonblank();
  500. static    void    old_entry();
  501. static    void    open_sty();
  502. static    int    page_diff();
  503. static    void    prepare_idx();
  504. static    void    process_idx();
  505. static    int    process_precedence();
  506. extern    void    qsort();
  507. static    void    qst();
  508. static    int    scan_alpha_lower();
  509. static    int    scan_alpha_upper();
  510. static    int    scan_arabic();
  511. static    int    scan_arg1();
  512. static    int    scan_arg2();
  513. static    int    scan_char();
  514. static    int    scan_field();
  515. extern    void    scan_idx();
  516. static    int    scan_key();
  517. static    int    scan_no();
  518. static    int    scan_roman_lower();
  519. static    int    scan_roman_upper();
  520. static    int    scan_spec();
  521. static    int    scan_string();
  522. extern    void    scan_sty();
  523. extern    void    sort_idx();
  524. extern    int    strtoint();
  525. static    void    wrap_line();
  526.  
  527. /* Miscellaneous standard library routines */
  528. char        *calloc();
  529. char        *getenv();
  530. char        *index();
  531. char        *malloc();
  532. char        *rindex();
  533. #endif
  534.